package project.parser.ast.aux;

import project.environments.DynamicEnv;
import project.environments.StaticEnv;
import project.environments.Value;
import project.parser.ast.exps.Exp;
import project.parser.ast.exps.Ident;
import project.parser.ast.types.Type;

public class FieldAST implements Field {
	private Type type;
	private final Ident id;
	private final Exp exp;

	public FieldAST(Ident id, Exp exp) {
		this.type = null;
		this.id = id;
		this.exp = exp;
	}

	@Override
	public Type typecheck(StaticEnv senv) {
		if (type == null) //se e' gia' stabilito il tipo non rifaccio il typecheck
			type = exp.typecheck(senv);
		return type;
	}

	@Override
	public Value evaluate(DynamicEnv denv) {
		return exp.evaluate(denv);
	}

	@Override
	public Ident getIdent() {
		return id;
	}

	@Override
	public String toString() {
		return id + ":" + exp;
	}
}
